Join Order and Indexes

If you are here, then you have a SQL that is not using an index. You have already:

If you have not checked these things, go back and do so before continuing.

Consider the following SQL

Let's assume the following:

The best result for this SQL is to read table_a retrieving rows where col5 matches the bind variable :x (an index on a.col5 will help, but is not mandatory), then for each row use an index to lookup table_b on each b.key. So what happens if Oracle doesn't do it this way? Some possibilities are:

If statistics on the tables are up to date and we are determined to use the index on table_b, then we must do two things to counteract the Cost Based Optimizer:

Check the execution plan with Explain Plan.

Is it using the index now? If not, then the index is somehow unusable - see your DBA. Even if it is now using the index, the Cost Based Optimiser thinks there is a better way. Do it the courtesy of comparing the SQL with and without hints.